package com.soft.springhrms.vo;

import com.fasterxml.jackson.annotation.JsonInclude;

public class ResultVO {
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private static final ResultVO DEFAULT_SUCCESS = new ResultVO(200, "success");
    private Integer code;
    private String message;
    private Object data;

    public ResultVO(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public ResultVO() {
    }

    // 返回默认成功的结果
    public static ResultVO success() {
        return DEFAULT_SUCCESS;
    }

    // 返回成功的结果（包含数据）
    public static ResultVO success(Object data) {
        ResultVO result = new ResultVO();
        result.code = 200;
        result.message = "success";
        result.data = data;
        return result;
    }

    // 返回成功的结果（包含数据和自定义消息）
    public static ResultVO success(Object data, String message) {
        ResultVO result = new ResultVO();
        result.code = 200;
        result.message = message;
        result.data = data;
        return result;
    }

    // 返回错误的结果
    public static ResultVO error(Integer code, String message) {
        ResultVO result = new ResultVO();
        result.code = code;
        result.message = message;
        return result;
    }

    // 返回带 Token 的成功结果
    public static ResultVO successWithToken(String token, Object userInfo) {
        ResultVO result = new ResultVO();
        result.code = 200;
        result.message = "登录成功";
        result.data = new TokenData(token, userInfo);  // 返回 Token 和用户信息
        return result;
    }

    // Getter 和 Setter 方法
    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public Object getData() {
        return data;
    }

    // Token 数据封装类
    public static class TokenData {
        private String token;
        private Object userInfo;

        public TokenData(String token, Object userInfo) {
            this.token = token;
            this.userInfo = userInfo;
        }

        public String getToken() {
            return token;
        }

        public Object getUserInfo() {
            return userInfo;
        }
    }
}
